<template>
  <div>
    <el-table
      :data="list"
      size="mini"
      height="200"
      stripe
      border
      style="width: 100%"
      @current-change="handleCurrentChange"
      @row-click="handleTableRow"
      highlight-current-row
    >
      <el-table-column
        prop="logContent"
        label="日志内容"
        width="180"
      ></el-table-column>
      <el-table-column prop="loginTime" label="日期" width="180"></el-table-column>
      
    </el-table>
 <div class="block" style="margin-top:15px;">
            <el-pagination align='center' @size-change="handleSizeChange" @current-change="handleCurrentChange" 
            :current-page="currentPage" 
            :page-sizes="[1,5,10,20]" 
            :page-size="pageSize" 
            layout="total, sizes, prev, pager, next, jumper" 
            :total="pages">
            </el-pagination>
        </div>
    <div class="block">
    <span class="demonstration">起始日期</span>
    <el-date-picker value-format="yyyy-MM-dd"
      v-model="value1"
      type="date"
      placeholder="选择日期">
    </el-date-picker>
    
  </div>
  <div class="block">
    <span class="demonstration">结束日期</span>
    <el-date-picker value-format="yyyy-MM-dd"
      v-model="value2"
      type="date"
      placeholder="选择日期">
    </el-date-picker>
  </div>
  <el-button type="primary" @click="find()">查询</el-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [],
      logParam: {
        pageNO: "1",
        pageSize: "3",
        start:"",
        end:""
      },
      pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          },
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }]
        },
        value1: '',
        value2: '',
        pages:'', //总页数
        pageNO:'',
        start:'',
        end:'',
        currentPage: 1, // 当前页码
        total: 20, // 总条数
        pageSize: 2 // 每页的数据条数
    };
  },
  methods: {
    async findByItem() {
      let list = await this.ajax.getSubmit(
        "/api/log/findByItem",
        this.logParam
      );
        console.log(list)
        this.pages = list.pages;
      this.list = list.records;
      console.log(this.list);
    },
    handleTableRow(row) {
      console.log(row.diseaseId);
      this.diseaseId = row.diseaseId;
    },
    handleCurrentChange(val) {
      this.currentRow = val;
      console.val;
    },
     //每页条数改变时触发 选择一页显示多少行
    async handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        let logParam = {pageNO:1,pageSize:val,start:'',end:''}
        let info = await this.ajax.getSubmit("/api/log/findByItem",logParam)
        console.log(info)
        this.list = info.records;
    },
    //当前页改变时触发 跳转其他页
    async handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.currentPage = val;
        let logParam = {pageNO:val,pageSize:3,start:'',end:''}
        let info = await this.ajax.getSubmit("/api/log/findByItem",logParam)
        console.log(info)
        this.list = info.records;
    },
    //模糊查询
    async find(){
        let start = this.value1
        console.log(start)
        let end = this.value2
        console.log(end)
        let logParam = {pageNO:1,pageSize:3,start:start,end:end}
        let info = await this.ajax.getSubmit("/api/log/findByItem",logParam)
        console.log(info)
        this.list = info.records;
    }
  },
  created(){
    this.findByItem()
  }
};
</script>

<style>

</style>